home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / HyperCuber Source / HyperCuber 2.0 Source.sit / HyperCuber 2.0 Source / CKeyPane.cp < prev    next >
Text File  |  1994-04-13  |  5KB  |  213 lines

  1. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. //| CKeyPane
  3. //|
  4. //| This implements a pane which displays a keyboard shortcut
  5. //|______________________________________________________________________
  6.  
  7. #include "CKeyPane.h"
  8. #include <CPaneBorder.h>
  9.  
  10. #include <string.h>
  11. #include <LoMem.h>
  12.  
  13.  
  14. //============================ external globals =======================\\
  15.  
  16. extern CBureaucrat *gGopher;
  17.  
  18.  
  19. //======================== Prototypes ========================\\
  20.  
  21. extern void GetKeyString(short keycode, char *key_name);
  22.  
  23.  
  24.  
  25. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  26. //| CKeyPane::IKeyPane
  27. //|
  28. //| Purpose: Initialize the key pane.
  29. //|
  30. //| Parameters: same as superclass
  31. //|_________________________________________________________
  32.  
  33. void CKeyPane::IKeyPane(CView *anEnclosure, CBureaucrat *aSupervisor, short aHEncl, short aVEncl,
  34.                         SizingOption aHSizing, SizingOption aVSizing, short line)
  35. {
  36.  
  37. #define PANE_WIDTH    50
  38. #define PANE_HEIGHT    16
  39.  
  40.     IEditText(anEnclosure, aSupervisor,                //  Call superclass' initialization routine
  41.                 PANE_WIDTH, PANE_HEIGHT, aHEncl, aVEncl,
  42.                     aHSizing, aVSizing, line);
  43.     SetAlignCmd(cmdAlignCenter);
  44.     SetFontNumber(systemFont);
  45.     SetFontSize(12);
  46.     Specify(kNotEditable, kNotSelectable,            //  No editing of this text
  47.                 kNotStylable);
  48.     SetWantsClicks(TRUE);                            //  But it accepts clicks
  49.  
  50.     CPaneBorder *border = new(CPaneBorder);
  51.     border->IPaneBorder(kBorderFrame);
  52.     SetBorder(border);
  53.  
  54. }    //==== CKeyPane::IKeyPane() ====\\
  55.  
  56.  
  57.  
  58. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  59. //| CKeyPane::Draw
  60. //|
  61. //| Purpose: This draws the pane.
  62. //|
  63. //| Parameters: none
  64. //|___________________________________________________________________________________
  65.  
  66. void CKeyPane::Draw(Rect *rect)
  67. {
  68.  
  69.     inherited::Draw(rect);                //  Draw the text in the pane
  70.  
  71.     if (this == gGopher)                //  Highlight if this is active
  72.         Highlight();
  73.         
  74. }    //==== CKeyPane::Draw() ====\\
  75.  
  76.  
  77.  
  78. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  79. //| CKeyPane::Highlight
  80. //|
  81. //| Purpose: This highlights the pane.
  82. //|
  83. //| Parameters: none
  84. //|___________________________________________________________________________________
  85.  
  86. void CKeyPane::Highlight(void)
  87. {
  88.  
  89.     Rect area;
  90.     LongToQDRect(&frame, &area);
  91.     BitClr(&HiliteMode, pHiliteBit);            //  Use color highlighting to highlight pane                                         
  92.     InvertRect(&area);
  93.  
  94. }    //==== CKeyPane::Highlight() ====\
  95.  
  96.  
  97. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  98. //| CKeyPane::Activate
  99. //|
  100. //| Purpose: This highlights the pane.
  101. //|
  102. //| Parameters: none
  103. //|___________________________________________________________________________________
  104.  
  105. void CKeyPane::Activate(void)
  106. {
  107.  
  108.     Prepare();
  109.     Rect area;
  110.     LongToQDRect(&frame, &area);
  111.     Draw(&area);                                //  Draw pane
  112.     
  113.     inherited::Activate();
  114.  
  115. }    //==== CKeyPane::Activate ====\\
  116.  
  117.  
  118.  
  119. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  120. //| CKeyPane::Deactivate
  121. //|
  122. //| Purpose: This de-highlights the pane.
  123. //|
  124. //| Parameters: none
  125. //|___________________________________________________________________________________
  126.  
  127. void CKeyPane::Deactivate(void)
  128. {
  129.  
  130.     Prepare();
  131.     Rect area;
  132.     LongToQDRect(&frame, &area);
  133.     Draw(&area);                                //  Draw pane
  134.     
  135.     inherited::Deactivate();
  136.  
  137. }    //==== CKeyPane::Deactivate ====\\
  138.  
  139.  
  140.  
  141. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  142. //| CKeyPane::DoClick
  143. //|
  144. //| Purpose: Handle a click in the pane.
  145. //|
  146. //| Parameters: none
  147. //|___________________________________________________________________________________
  148.  
  149. void CKeyPane::DoClick(Point hitPt, short modifierKeys, long when)
  150. {
  151.  
  152.     BecomeGopher(TRUE);                            //  Make this pane the gopher
  153.  
  154. }    //==== CKeyPane::DoClick ====\\
  155.  
  156.  
  157.  
  158. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  159. //| CKeyPane::DoKeyDown
  160. //|
  161. //| Purpose: This procedure handles a key down event.
  162. //|
  163. //| Parameters: the_char: character associated with key
  164. //|             key_code: the key code of the key
  165. //|             event:    the keydown event
  166. //|______________________________________________________________________
  167.  
  168. void    CKeyPane::DoKeyDown(char the_char, Byte key_code, EventRecord *event)
  169. {
  170.  
  171.     SetKey(key_code);                        //  Set the value of pane to the pressed key
  172.  
  173. }    //==== CKeyPane::DoKeyDown() ====\\
  174.  
  175.  
  176.  
  177. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  178. //| CKeyPane::GetKey
  179. //|
  180. //| Purpose: Get the current value of the keyboard shortcut
  181. //|
  182. //| Parameters: returns the key code of the current shortcut
  183. //|_______________________________________________________________________
  184.  
  185. short CKeyPane::GetKey(void)
  186. {
  187.  
  188.     return code;
  189.  
  190. }    //==== CKeyPane::GetKey() ====\\
  191.  
  192.  
  193.  
  194. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  195. //| CKeyPane::SetKey
  196. //|
  197. //| Purpose: Set the keyboard shortcut to a new value
  198. //|
  199. //| Parameters: keycode: the new shortcut
  200. //|_______________________________________________________________________
  201.  
  202. void CKeyPane::SetKey(short keycode)
  203. {
  204.  
  205.     code = keycode;                                //  Save the key code
  206.  
  207.     char    key_name[10];
  208.     GetKeyString(keycode, key_name);            //  Get the key as a string
  209.     
  210.     SetTextPtr(key_name, strlen(key_name));        //  Set the pane to display the string
  211.  
  212. }    //==== CKeyPane::SetKey() ====\\
  213.